<template>
  <!-- tab 切换组件 -->
  <div class="tab-bar">
    <div class="tabs flex">
      <div
        @click="tabChange(item, i)"
        class="tab-item font18"
        :class="{ active: i === tabIndex }"
        v-for="(item, i) in list"
        :key="i"
      >
        {{ item.name }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "tabBar",
  props: {
    list: {
      type: Array,
      default: [],
    },
    activeIndex: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      tabIndex: 0,
    };
  },
  watch: {
    activeIndex(newVal) {
      this.tabIndex = newVal;
    },
  },
  created() {},
  methods: {
    tabChange(item, i) {
      this.tabIndex = i;
      this.$emit("change", {
        tab: item,
        index: i,
      });
    },
  },
};
</script>

<style scoped lang="scss">
.tab-bar {
  padding: 0 20px;
  background-color: $fff;
  height: 40px;
  border-top: 1px solid rgba(219, 219, 219, 0.9);
  .tab-item {
    color: $color666;
    margin-right: 20px;
    line-height: 40px;
    border-top: 2px solid transparent;
    border-left: 1px solid transparent;
    border-right: 1px solid transparent;
    padding: 0 10px;
    cursor: pointer;
    &:first-of-type {
      margin-left: 20px;
    }
    &.active {
      color: $defaultTxtColor;
      font-weight: bold;
      border-top: 2px solid $acativeTxtColor;
      border-left: 1px solid #E1E1E1;
      border-right: 1px solid #E1E1E1;
      
    }
  }
}
</style>
